<?php
/**
 * Description: 获取收货地址 - 省份
 * User: devforma
 * Date: 15/8/4
 * Time: 11:48
 */

class GetCountries implements iController {

    /**
     * api请求处理主函数
     * @param array $queryArgs 就是$_REQUEST变量
     * @return array api返回结果，必须含response_code
     */
    public function output($queryArgs) {
        global $cmsdb;

        if (empty($queryArgs['city']))
            return genOutput(1000);

        $sql = "SELECT DISTINCT(`country`) FROM `address` WHERE `city`=:city";

        $list = $cmsdb->getCol($sql, array(':city' => $queryArgs['city']));

        if (is_array($list)) {
            foreach ($list as &$l) {
                $l = str_replace(array('（', '）'), array('(', ')'), $l);
                $l = preg_replace('/\(.*\)/', '', $l);
            }
        }

        return genOutput(1, array(
            'list' => array_values(array_unique((array)$list))
        ));
    }
}

